package com.itheima.redbaby.utils;

import android.graphics.Bitmap;
import android.widget.ImageView;

import com.itheima.redbaby.GloableParams;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapCommonUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;

/**
 * 图片工具
 * @author ShinHye
 * 2014-10-11 下午5:44:20
 */
public class ImageUtil {
	
	/**
	 * 从网络加载图片
	 * @param iv
	 * @param url
	 */
	public static void loadImageFromUrl(ImageView iv, String url) {
        BitmapUtils bitmapUtils = new BitmapUtils(GloableParams.context);
        
        BitmapDisplayConfig bigPicDisplayConfig = new BitmapDisplayConfig();
        bigPicDisplayConfig.setBitmapConfig(Bitmap.Config.RGB_565);
        bigPicDisplayConfig.setBitmapMaxSize(BitmapCommonUtils.getScreenSize(GloableParams.context));

//        BitmapLoadCallBack<ImageView> callback = new DefaultBitmapLoadCallBack<ImageView>() {
//            @Override
//            public void onLoadStarted(ImageView container, String uri, BitmapDisplayConfig config) {
//                container.setImageResource(R.drawable.product_loading);
//                Toast.makeText(GloableParams.context, uri, 300).show();
//            }
//
//            @Override
//            public void onLoadCompleted(ImageView container, String uri, Bitmap bitmap, BitmapDisplayConfig config, BitmapLoadFrom from) {
//                container.setImageBitmap(bitmap);
//                Toast.makeText(GloableParams.context, bitmap.getWidth() + "*" + bitmap.getHeight(), 300).show();
//            }
//        };

        bitmapUtils.display(iv, url, bigPicDisplayConfig, null);
	}

}
